﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class UserControl_PCBAging : System.Web.UI.UserControl
{
    PCBAging ag;
    PCBAgingInfo agi;
    AgingItem agitem;
    IList<PCBAgingInfo> agis;
    private string _pCBAgingID;

    public string pCBAgingID
    {
        get
        {
            return _pCBAgingID;
        }
        set
        {
            _pCBAgingID = value;
        }
    }

    public UserControl_PCBAging()
    {
        ag = new PCBAging();
        agitem = new AgingItem();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        BindAging();
        BindAgingItem();
    }

    protected void BindAging()
    {
        if (!string.IsNullOrEmpty(pCBAgingID))
        {
            agi = ag.GetbyPCBAgingID(pCBAgingID);
            agis = new List<PCBAgingInfo>();
            agis.Add(agi);
            this.DetailsView2.DataSource = agis;
            this.DetailsView2.DataBind();
            this.DetailsView2.Visible = true;
            this.DetailsView4.DataSource = agis;
            this.DetailsView4.DataBind();
            this.DetailsView4.Visible = true;
            this.DetailsView9.DataSource = agis;
            this.DetailsView9.DataBind();
            this.DetailsView9.Visible = true;
        }
    }

    protected void BindAgingItem()
    {
        List<AgingItemInfo> list = (List<AgingItemInfo>)agitem.GetPCBAgingItemsbyID(pCBAgingID);
        this.ListBox1.DataSource = list;
        this.ListBox1.DataTextField = "ProductSN";
        this.ListBox1.DataBind();
        this.Label1.Text = list.Count.ToString();
    }

    protected void DetailsView4_DataBound(object sender, EventArgs e)
    {
        checkformat(sender);
    }

    protected void DetailsView9_DataBound(object sender, EventArgs e)
    {
        checkformat(sender);
    }

    protected static void checkformat(object sender)
    {
        DetailsView d = (DetailsView)sender;
        if (d.Rows[0].Cells[1].Text == "1900/1/1 0:00:00" && d.Rows[2].Cells[1].Text == "0.00" && d.Rows[3].Cells[1].Text == "0.00")
        {
            d.Rows[0].Cells[1].Text = "";
            d.Rows[2].Cells[1].Text = "";
            d.Rows[3].Cells[1].Text = "";
        }
    }

    protected void DetailsView2_DataBound(object sender, EventArgs e)
    {
        DetailsView d = (DetailsView)sender;
        d.Rows[5].Cells[1].Text = "24小时";
        d.Rows[6].Cells[1].Text = "65℃";
    }
}
